$(document).ready(function(e) {
	
		//  播放控制
		var myAudio = $(".music_room_bo audio")[0];
		var $sourceList = $(".music_room_bo source");
		var currentSrcIndex = 0;
		var currentSr = "";
		$(".btn_play").click(function(){
			if (myAudio.paused) {
				myAudio.play();
				dragMove();
				timeChange();
				$(this)[0].src="images/bofan.png";
			} else {
				myAudio.pause();
				$(this)[0].src="images/Play_626px_1183566_easyicon.png";
			}
			
		});
		
		$(".btn_next").click(function(){
			/*++currentSrcIndex > $sourceList.length - 1 && (currentSrcIndex = 0);
			currentSrc = $(".music_room_bo source").eq(currentSrcIndex).prop("src");
			myAudio.src = currentSrc;
			myAudio.play();*/

			if(myAudio.currentTime<myAudio.duration){
				myAudio.currentTime=myAudio.currentTime+10;
				alert(myAudio.currentTime);
				timeChange();
				dragMove();

			}
		});
		$(".btn_fast").click(function(){
			/*--currentSrcIndex < 0 && (currentSrcIndex = 0);
			currentSrc = $(".music_room_bo source").eq(currentSrcIndex).prop("src");
			myAudio.src = currentSrc;
			myAudio.play();*/
			alert(myAudio.currentTime)
			if(myAudio.currentTime>10){
				myAudio.currentTime=10;
				alert(myAudio.currentTime);
					timeChange();
					dragMove();

			}
		});
		

	var   sli=$(".slider")[0],
	      bas=$(".base_bar"),
		  pro=$(".progress_bar")[0];
		function dragMove() {
				setInterval(function() {
					
					sli.style.left =(myAudio.currentTime / myAudio.duration)*(bas.width())-5+"px";
					pro.style.width =(myAudio.currentTime / myAudio.duration)*(bas.width())-5+"px";
					 /*-((window.innerWidth) - (myAudio.currentTime / myAudio.duration) * (window.innerWidth - 1000)) + "px";*/
				}, 1000);
			}
			//播放时间
	function timeChange() {//默认获取的时间是时间戳改成我们常见的时间格式
		 window.setInterval(function(){
		var timePlace = $('.total_time');
		var timePlace_current = $('.passed_time');
		//分钟
		var time=myAudio.duration;
		var time_current=myAudio.currentTime ;
		
		var minute = time / 60;
		var minute_current = time_current / 60;
		var minutes = parseInt(minute);
		
		var minutes_current = parseInt(minute_current);
		
		if (minutes < 10) {
			minutes = "0" + minutes;
		}
		if (minutes_current < 10) {
			minutes_current = "0" + minutes_current;
		}
		//秒
		
		var second = time % 60;
		seconds = parseInt(second);
		if (seconds < 10) {
			seconds = "0" + seconds;
		}
		var second_current = time_current % 60;
		seconds_current = parseInt(second_current);
		if (seconds_current < 10) {
			seconds_current = "0" + seconds_current;
		}
		var allTime = "00"+""+":"+""+ minutes + "" + ":" + "" + seconds + ""
		timePlace.text(allTime) ;
		var allTime_current = "00"+""+":"+""+ minutes_current + "" + ":" + "" + seconds_current + ""
		timePlace_current.text(allTime_current);
		$('.music_time h2').text(allTime_current);
		if(myAudio.duration==myAudio.currentTime){
			myAudio.pause();
				$(".btn_play")[0].src="images/Play_626px_1183566_easyicon.png";
			}
	},500);
}

		$(".slider").mousedown(starDrag = function(ev) {
			ev.preventDefault();
			var origLeft = $(this).position().left;      /*滑块初始位置*/
			var origX = ev.clientX; /*鼠标初始位置*/
			var target = this;
			var progress_bar = $(".progress_bar")[0];
			$(document).mousemove(doDrag = function(ev){
				ev.preventDefault();
				var moveX = ev.clientX - origX;        /*计算鼠标移动的距离*/
				var curLeft = origLeft + moveX; /*用鼠标移动的距离表示滑块的移动距离*/
				(curLeft < -1) && (curLeft = -1);
				(curLeft > 420) && (curLeft = 420);
				target.style.left = curLeft + "px";
				progress_bar.style.width = curLeft + "px";
				var pro_width=curLeft;
				var bas_width=bas.width();
				myAudio.currentTime=(pro_width/bas_width)*myAudio.duration;
			    timeChange();
				dragMove();
				
				//myAudio.changeVolumeTo((curLeft + 7)/100);
			});
			$(document).mouseup(stopDrag = function(){
				$(document).unbind("mousemove",doDrag);
				$(document).unbind("mouseup",stopDrag);
			});
		});

}); 
